<?php
namespace Admin\Controller;
use Think\Controller;
class CommentController extends baseActionController {
    public function commentList(){
		 // 实例化User对象
		$User = M('comment'); // 实例化User对象
		$where="";
		if(!empty($_POST["uname"]))
		{
			$uname=$_POST["uname"];

			$where=$where."uname='{$uname}' and";
		}
		if(!empty($_POST["review"])&&$_POST["review"]!="0")
		{
			$review=$_POST["review"];

			$where=$where." review='$review' and";
		}

		if(!empty($_POST["fid"])&&$_POST["fid"]!="0")
		{
			$fid=$_POST["fid"];
			
			$where=$where." fid='$fid' and";
		}
		$where = substr($where,0,-4);
		$list = $User->where($where)->page($_GET['p'],6)->select();
		$pro = json_decode($list["pro"],true);
		$this->assign('res',$list);
		$this->assign('pro',$pro);
		$shu = $User->count();
		$this->assign('s',$shu);
		$count = $User->where($where)->count();// 查询满足要求的总记录数
		$Page = new \Think\Page($count,6);// 
			foreach($where as $key=>$val) {   
				$Page->parameter[$key] = urlencode($val);   
			}
		$Page->setConfig('header', '<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('first','首页');
		$Page->setConfig('last','尾页');
		$Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
		$Page->lastSuffix = false;//最后一页不显示为总页数
		$show = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->display(); // 输出模板
	}
	
	public function Del(){
		$odid = I('post.arr');
		$n = count($odid);
		foreach($odid as $v){
		$res = M('order')->where("id={$v}")->delete();
		}
		$r = array();
		if($res){
			$r['msg']='已成功删除'.$n.'条记录';
			$r['status']=true;
		}else{
			$r['msg']='删除失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}
	public function orderDel(){	
			$oid = I('id');
			$res = M('order')->delete($oid);
			$r = array();
			if($res){
				$r['msg']='删除成功';
				$r['status']=true;
			}else{
				$r['msg']='删除失败';
				$r['status']=false;
			}
		$this->ajaxReturn($r);
		
	}

	public function chaxun(){
		$id = I('id');
		$res = M('comment')->find($id);
		//$this->assgin("arr",$res);
		$this->ajaxReturn($res);
	}

	public function view(){
		$order = D('order');
		$order->create($_POST);	
		if($order->save()){
			$r['msg']='发货成功';
			$r['status']=true;
		}else{
			$r['msg']='发货失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);	
	}
	public function commentdetail(){
		$id = I('id');
		$re = M('comment')->find($id);
		$this->assign("vo",$re);
		$this->display();
	}
	public function edit(){
		$order = D('order');
		$order->create($_POST);	
		if($order->save()){
			$r['msg']='修改成功';
			$r['status']=true;
		}else{
			$r['msg']='修改失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);	
	}
	public function search1(){
		$term = I('get.term');
		$res = M('comment')->field('uname')->where(array('uname'=>array('like',"%{$term}%")))->select();
		$str = "[";
		foreach($res as $v){
			$str .='"'.$v['uname'].'",';
		}
		$str = rtrim($str,',');
		$str .="]";
		echo $str;
	}

	public function comQx(){
		$oid = I("get.id");
		$res = D('comment');		
		$r = array();
		if($res->where(array("id"=>"{$oid}"))->save(array("review"=>"3"))){
			$r['msg']='评论已取消';
			$r['status']=true;
		}else{
			$r['msg']='评论取消失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}

	public function comQr(){
		$oid = I("get.id");
		$res = D('comment');		
		$r = array();
		if($res->where(array("id"=>"{$oid}"))->save(array("review"=>"1"))){
			$r['msg']='确认成功';
			$r['status']=true;
		}else{
			$r['msg']='确认失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}


	public function comHf(){
		$oid = I("get.id");
		$huifu = I("get.huifu");
		$res = D('comment');		
		$r = array();
		if($res->where(array("id"=>"{$oid}"))->save(array("review"=>"4","huifu"=>"{$huifu}"))){
			$r['msg']='回复成功';
			$r['status']=true;
		}else{
			$r['msg']='回复失败';
			$r['status']=false;
		}
		$this->ajaxReturn($r);
	}


}